<?php require '../../sesionabierta.php'; ?>
<?php include '../../../conexionbd/conexion.php';?>
<!DOCTYPE html>
<html lang="en">
<?php require '../../cabecera.php';?>
  <body>
    <?php include '../../modulos.php'; ?>  
    <div class="container">
      <div class="row-fluid">
          <div class="hero-unit">
              <h3>Eliminar Proveedor</h3>
              <form name="form_edit" method="POST" action="eliminarproveedor.php">
                  <table border="1" class="table table-bordered table-condensed">
                      <thead>
                          <tr>
                              <th>Nº Proveedor</th>
                              <th>Nombre</th>
                              <th>Telefono</th>
                              <th>Nit</th>
                              <th>Direccion</th>
                              <th>NRC</th>
                          </tr>
                      </thead>
                      <tbody>
                        <?php            
                            $id_proveedor = $_POST["id"];
                            $consulta = "SELECT * FROM proveedores WHERE id_proveedor = $id_proveedor";
                            $result = mysql_query($consulta, $enlace);
                
                            if (mysql_num_rows($result)== 0) {
                                echo '<center><h3><font color="red">No existe el c&oacute;digo buscado...</font></h3></center>';
                            }  else {
                                while ($row = mysql_fetch_array($result)) {
                                    $id = $row['id_proveedor'];
                                    $nombre = $row['nombre'];
                                    $telefono = $row['telefono'];
                                    $nit = $row['nit'];
                                    $direccion = $row['direccion'];
                                    $nrc = $row['nrc'];
                                }
                            }
                          ?>
                          <tr><input type="hidden" name="id" value="<?php echo $id?>"/>
                              <td><?php echo $id; ?></td>
                              <td><?php echo $nombre; ?></td>
                              <td><?php echo $telefono;?></td>
                              <td><?php echo $nit;?></td>
                              <td><?php echo $direccion;?></td>
                              <td><?php echo $nrc;?></td>
                            </tr>
                      </tbody>
                  </table>
                  <input type="submit" name="eliminar" value="Eliminar" class="btn btn-danger" onclick="return confirm('Este proveedor sera elimanado, ¿desea continuar?')"/>
                  <a href="listadoProveedores.php" class="btn">Regresar</a>
              </form>
            <?php 
              if (isset($_POST['eliminar'])) {
                $guardar = $_POST['eliminar'];

                    if ($guardar == "Eliminar"){
                        $id = $_POST['id'];

                    $eliminar = "DELETE FROM proveedores WHERE id_proveedor = $id";

                    $query = mysql_query($eliminar, $enlace);
                    if (!$query) {
                        echo 'No se elimino'.mysql_error();
                    }  else {   
                         echo "<script>alert('Proveedor eliminado');window.location.href=\"listadoProveedores.php\"</script>";
                    }       
                }
              }            
              ?>
          </div>      
      </div>
      <hr>
      <footer>
        <center><p>&copy; Conexi&oacute;n 2013</p></center>
      </footer>
    </div><!--/.fluid-container-->
    <script src="../../../js/jquery.js"></script>
    <script src="../../../js/bootstrap-dropdown.js"></script>
  </body>
</html>
